<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-dialog
        title="请选择打印模板"
        :visible.sync="crud.printConfig.pringDialog"
        width="30%"
      >
        <jPrintConfig groupId="wareAllot"
                      v-if="crud.printConfig.pringDialog"
                      @getPrintId="crud.toPrint"
                      :isPreview="crud.printConfig.isPreview"
        ></jPrintConfig>
      </el-dialog>
    <crudOperation :permission="permission">
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="primary"
        @click="crud.toDetail('wareAllotDetail')"
      >
        新增
      </el-button>
      <el-button
        slot="right"
        class="filter-item"
        size="mini"
        type="success"
        :disabled="crud.selections.length !== 1"
        :loading="crud.passLoading"
        @click="handleClickPassOut()"

      >
        <!--        v-permission="permission.pass"-->
        审核出库
      </el-button>
      <el-button
        slot="right"
        class="filter-item"
        size="mini"
        type="info"
        :loading="crud.rejectLoading"
        :disabled="crud.selections.length !== 1"
        @click="handleClickPassIn()"

      >
        <!--        v-permission="permission.reject"-->
        审核入库
      </el-button>
    </crudOperation>
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="100px" v-formkey="{query:toQuery}">
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="业务日期">
                <el-date-picker
                  v-model="query.dataExtent"
                  type="daterange"
                  @change="getValue()"
                  align="right"
                  unlink-panels
                  style="width: 100%"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  range-separator=""
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="pickerOptions">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="编码">
                <el-input     style="width: 100%" v-model="query.code"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="入库仓库">
                <zSelect    style="width: 100%" :value.sync="query.inWarehouseId" url="api/dropDown/basWarehouseList" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="出库仓库">
                <zSelect     style="width: 100%" :value.sync="query.outWarehouseId" url="api/dropDown/basWarehouseList" />
              </el-form-item>
            </el-col>
            </el-row>
            <el-row :gutter="10" style="text-align: center">
            <el-col :span="6">
              <el-form-item label="来源类型">
                <el-select
                  v-model="query.sourceType"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.t_buy_order_source_type"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="商品">
                <zSelect :value.sync="query.goodsId" url="api/dropDown/basGoodsList" style="width: 100%;"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="商品品牌">
                <zSelect :value.sync="query.goodsBrandId"     style="width: 100%"  url="api/dropDown/basGoodsBrandList" >
                </zSelect>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="状态">
                <el-select
                  v-model="query.orderStatus"
                  class="filter-item"
                  clearable
                  placeholder="状态"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_order_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="调拨类型">
                <el-select
                  v-model="query.type"
                  class="filter-item"
                  clearable
                  placeholder="调拨类型"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.t_ware_allot_type"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="备注">
                <el-input     style="width: 100%"  v-model="query.remark"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据说明">
                <el-input     style="width: 100%"  v-model="query.orderRemark"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table"  border
                height="700"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler"
                @row-dblclick="crud.toDetailPlus('wareAllotDetail',$event.id)">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60" />
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 0px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 0px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>

        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="单据编码" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('busDate')" prop="busDate" label="业务日期">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.busDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sourceType')" prop="sourceType" label="来源类型">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ dictName(dict.t_ware_allot_source_type,scope.row.sourceType)  }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sourceCode')" prop="sourceCode" label="来源单据号"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('type')" prop="type" label="调拨单类型">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ dictName(dict.t_ware_allot_type,scope.row.type)  }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('receiveDate')" prop="receiveDate" label="应收日期">&ndash;&gt;-->
<!--&lt;!&ndash;          <template slot-scope="scope">&ndash;&gt;-->
<!--&lt;!&ndash;            <span>{{ parseTime(scope.row.receiveDate) }}</span>&ndash;&gt;-->
<!--&lt;!&ndash;          </template>&ndash;&gt;-->
<!--&lt;!&ndash;        </el-table-column>&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('outWarehouseName')" prop="outWarehouseName" label="出库仓库" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('inWarehouseName')" prop="inWarehouseName" label="入库仓库" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('outDeptName')" prop="outDeptName" label="调出部门" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('inDeptName')" prop="inDeptName" label="调入部门" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('count')" prop="count" label="条数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="箱数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxAmount')" prop="taxAmount" label="含税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('printCount')" prop="printCount" label="打印次数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('orderStatus')" prop="orderStatus" label="状态" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ dictName(dict.common_order_status,scope.row.orderStatus) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('tax')" prop="tax" label="税额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('orderRemark')" prop="orderRemark" label="单据说明" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserName')" prop="createUserName" label="添加人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createTime')" prop="createTime" label="添加时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.createTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserName')" prop="updateUserName" label="修改人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateTime')" prop="updateTime" label="修改时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.updateTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('auditUserName')" prop="auditUserName" label="审核人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('auditTime')" prop="auditTime" label="审核时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.auditTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('closeUserName')" prop="closeUserName" label="关闭人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('closeTime')" prop="closeTime" label="关闭时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.closeTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWareAllot from '@/api/erp/wareAllot'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudWareSalesInvoicePick from '@/api/erp/wareSalesInvoicePick'

import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";
import jPrintConfig from '@/components/jPrintConfig/jPrintConfig'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '调拨单',name:'wareAllot', url: 'api/wareAllot', sort: 'id,desc',  optShow: {
    add: false,
    edit: false,
    del: true,
    download: true,
    leadingIn: true,
    enable: false,
    disable: false,
    pass: true,
    reject: true,
    print: true,
    printDetail: true
  },crudMethod: { ...crudWareAllot }})
const defaultForm = { id: null, code: null, name: null, type: null, busDate: null, receiveDate: null, sourceType: null, sourceId: null, sourceCode: null, serialNumber: null, outDeptId: null, outDeptCode: null, outDeptName: null, outWarehouseId: null, outWarehouseCode: null, outWarehouseName: null, inDeptId: null, inDeptCode: null, inDeptName: null, inWarehouseId: null, inWarehouseCode: null, inWarehouseName: null, count: null, boxCount: null, taxAmount: null, noTaxAmount: null, tax: null, isPrint: null, printCount: null, seq: null, orderStatus: null, remark: null, orderRemark: null, version: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null, auditUserId: null, auditUserCode: null, auditUserName: null, auditTime: null, closeUserId: null, closeUserCode: null, closeUserName: null, closeTime: null }
export default {
  name: 'WareAllot',
  components: { pagination, crudOperation, rrOperation, udOperation,jTableColumnConfig, jPrintConfig },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ['t_buy_order_source_type','common_order_status','t_ware_allot_type','t_ware_allot_source_type'],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      permission: {
        add: ['admin', 'wareAllot:add'],
        edit: ['admin', 'wareAllot:edit'],
        del: ['admin', 'wareAllot:del'],
        import: ['admin', 'wareAllot:import'],
        export: ['admin', 'wareAllot:export'],
        copy: ['admin', 'wareAllot:copy'],
        upload: ['admin', 'wareAllot:upload'],
        download: ['admin', 'wareAllot:download'],
        pass: ['admin', 'wareAllot:pass'],
        reject: ['admin', 'wareAllot:reject'],
        closed: ['admin', 'wareAllot:closed'],
        invalid: ['admin', 'wareAllot:invalid'],
        stop: ['admin', 'wareAllot:stop'],
        recover: ['admin', 'wareAllot:recover'],
      },
      rules: {
      }    }
  },
  watch: {
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    getValue(e){
      this.query.startTime =this.query.dataExtent[0]
      this.query.endTime =this.query.dataExtent[1]
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    // 审核出库
    handleClickPassOut(){
      let ids = []
      this.crud.selections.map((item) => {
        ids.push(Number(item.id))
      })
      let data ={ids:ids}
      crudWareAllot.passOut(data).then(res => {
        this.$message({
          type: 'success',
          message: '审核出库成功!'
        });
      }).catch((res)=>{
      })
    },
    handleClickPassIn(){
      let ids = []
      this.crud.selections.map((item) => {
        ids.push(Number(item.id))
      })
      let data ={ids:ids}
      crudWareAllot.passIn(data).then(res => {
        this.$message({
          type: 'success',
          message: '审核入库成功!'
        });
      }).catch((res)=>{
      })
    }
  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
